package com.huadao.cart_ccs.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import com.huadao.cart_ccs.R;

public class CircularVG extends View {

    private int radius;
    private int color;
    public CircularVG(Context context) {
        super(context);
    }

    public CircularVG(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initAttrs(context,attrs);
    }

    public CircularVG(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
//        super(context, attrs, defStyleAttr);
        super(context, attrs);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int verticalCenter = getHeight() / 2;
        int horizontalCenter = getWidth() / 2;
//        int circleRadius = 200;
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(color);
        canvas.drawCircle(horizontalCenter, verticalCenter, radius, paint);
    }

    private void initAttrs(Context context,AttributeSet attrs){
        TypedArray array=context.obtainStyledAttributes(attrs, R.styleable.MultiStateTextView);
        radius=array.getInt(R.styleable.CircularVG_radius,0);
        color=array.getInt(R.styleable.CircularVG_color,Color.BLACK);
    }
}
